﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;

namespace SurroundCat
{
    public class RicInfo
    {
        public RicInfo(double dia, Point s, string color = "#BAD9FF")
        {
            var radius = dia / 2;
            Control = new Ellipse();
            Control.Width = dia;
            Control.Height = dia;
            Control.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString(color));

            Site = s;
            Position = new Point(Site.X + radius, Site.Y + radius);


            Control.MouseDown += (se, e) => { SetIntercept?.Invoke(this); };

        }
        public event Action<RicInfo> SetIntercept;

        private bool isWall = false;
        public bool IsWall
        {
            get { return isWall; }
            set
            {
                isWall = value;
                if (value)
                    Control.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#133267"));
                else
                    Control.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#BAD9FF"));
            }
        }

        private bool isRoute = false;
        public bool IsRoute
        {
            get { return isRoute; }
            set
            {
                isRoute = value;
                if (value)
                    Control.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFB6C1"));
                else
                    Control.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#BAD9FF"));
            }
        }

        public Point Position { get; set; }

        private Point site;
        public Point Site
        {
            get { return site; }
            set { site = value; Canvas.SetTop(Control, Site.Y); Canvas.SetLeft(Control, Site.X); }
        }

        public Point Coordinate { get; set; }
        public Ellipse Control { get; set; }

        public int H { get; set; }

        public TextBlock SetC(int c)
        {
            List<int> vs = new List<int>() { (int)Coordinate.X, (int)Coordinate.Y, Math.Abs((int)Coordinate.X - c - 1), Math.Abs((int)Coordinate.Y - c - 1) };
            vs.Sort();
            H = vs.First();
            if (H >= 6)
            {
            }
            TextBlock nodeText = new TextBlock();
            nodeText.Text = H.ToString();

            Canvas.SetTop(nodeText, Site.Y);
            Canvas.SetLeft(nodeText, Site.X);
            return nodeText;
        }

    }
}
